package dev.werillib.android

import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager

fun showKeyboard(view: View) {
    val imm: InputMethodManager? = view.context
        .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    if (imm != null) {
        view.requestFocus()
        imm.showSoftInput(view, 0)
    }
}

fun hideKeyboard(view: View) {
    val imm: InputMethodManager? = view.context
        .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm?.hideSoftInputFromWindow(view.windowToken, 0)
}

fun toggleSoftInput(view: View) {
    val imm: InputMethodManager? = view.context
        .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm?.toggleSoftInput(0, 0)
}